package com.handle;

import com.channel.ChannelContent;
import com.message.register.RpcRegisterResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author linyu.dai
 * @project rpc
 * @description 获取注册响应
 * @creat 2022/11/27 16:56:36
 */
@Slf4j
public class RegisterResponseHandle extends SimpleChannelInboundHandler<RpcRegisterResponse> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcRegisterResponse msg) throws Exception {
        //如果没有错误
        if(msg.getErrorMessage().isEmpty()){
            log.info("注册成功 开始连接服务{}",msg);
            //初始化服务连接
            ChannelContent.init(msg.getRegisterInfo());
        }else{
            log.info("注册失败 端口注册中心{}",msg);
            //关闭连接注册中心的channel
            ctx.channel().close();
        }
    }

}
